define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'refund/refundorder/index' + location.search,
                    // add_url: 'refund/refundorder/add',
                    edit_url: 'refund/refundorder/edit',
                    // del_url: 'refund/refundorder/del',
                    // multi_url: 'refund/refundorder/multi',
                    // import_url: 'refund/refundorder/import',
                    table: 'refundorder',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'sn', title: __('订单编号'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.mobile', title: __('用户'),operate: false},
                        // {field: 'user_level', title: __('User_level')},
                        // {field: 'schedule_id', title: __('Schedule_id')},
                        {field: 'hall.name', title: __('影厅'),operate: false},
                        {field: 'film.name', title: __('影片'),operate: false},
                        {field: 'schedule.date', title: __('日期'),operate: false},
                        {field: 'schedule.start_time', title: __('开始时间'),operate: false},
                        {field: 'ticket_num', title: __('票数'),operate: false},
                        // {field: 'cinema_name', title: __('Cinema_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'cinema_address', title: __('Cinema_address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN'},
                        {field: 'total_fee', title: __('支付金额'), operate:false},
                        // {field: 'discount', title: __('Discount'), operate:'BETWEEN'},
                        // {field: 'after_discount_fee', title: __('After_discount_fee'), operate:'BETWEEN'},
                        // {field: 'coupon_id', title: __('Coupon_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'coupon_fee', title: __('Coupon_fee'), operate:'BETWEEN'},
                        {field: 'pay_type', title: __('支付方式'), searchList: {"wechat":__('微信'),"money":__('余额'),"give_money":__('赠送余额'),"system": __('后台购买'),"adapay_wx_pub": 'adapay微信'}, formatter: Table.api.formatter.normal},
                        // {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'refund_status', title: __('退款状态'), searchList: {"-1":__('拒绝'),"1":__('审核中'),"2":__('同意')}, formatter: Table.api.formatter.status},
                        {field: 'refund_fee', title: __('退款金额'), operate:false},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                            formatter:function (value, row, index) {
                                var that = $.extend({},this);
                                var table = $(this.table).clone(true);
                                //后端传之判断是否有编辑、删除操作权限
                                // console.log(row.status);
                                if(row.refund_status ==-1 || row.refund_status == 2){
                                    $(table).data('operate-del',null);
                                }
                                that.table = table;
                                return Table.api.formatter.operate.call(that,value,row,index);
                            },
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
